/*
 *   MetrixViewer - A simple app for viewer Metrix data. Uses XML data from Webosroundup's Metrix data and graphs it using Google charts API.
 *   http://code.google.com/p/metrixviewer/
 *   Copyright (C) 2010  Wes Brown
 *
 *   This program is free software; you can redistribute it and/or modify
 *   it under the terms of the GNU General Public License as published by
 *   the Free Software Foundation; either version 2 of the License, or
 *   (at your option) any later version.
 *
 *   This program is distributed in the hope that it will be useful,
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *   GNU General Public License for more details.
 *
 *   You should have received a copy of the GNU General Public License along
 *   with this program; if not, write to the Free Software Foundation, Inc.,
 *   51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 */
 
function AllDataAssistant() {

	this.dateList = [];
	this.activityList = [];
	this.deviceList = [];
	this.carrierList = [];
	this.resolutionList = [];
	this.localeList = [];
	this.appVersionList = [];
	this.webosBuildList = [];
	this.webosVersionList = [];
	this.custom1List = [];
	this.custom2List = [];
	this.custom3List = [];
	this.custom4List = [];
	
	this.totalCount = 0;

}

AllDataAssistant.prototype.setup = function() {

	//Bottom of page menu widget
	this.commandMenuModel = {
		visible: true,
		items: [
			{ label: $L('Launch'), command: 'do-launch', width: 100},
			//{ icon: "refresh", command: 'do-refresh' } ,
			//{ icon: "info", command: 'do-custom' } ,
			{ label: $L('Custom'), command: 'do-custom', width: 100},
			{ label: $L('Catalog'), command: 'do-catalog', width: 100 }
		]
	};
	this.controller.setupWidget( Mojo.Menu.commandMenu, {menuClass: 'no-fade'}, this.commandMenuModel );

	
/*
	//Date drawer and list
	this.controller.setupWidget("dateDrawer",
		this.dateAttributes = {
			modelProperty: 'open',
			unstyled: true
		},
		this.dateModel = {
			open: false
		}
	);
	this.dateDrawer = this.controller.get("dateDrawer");
	this.controller.listen(this.controller.get("dateGroup"),Mojo.Event.tap,this.toggleDateDrawer.bindAsEventListener(this));
	
	this.dateListAttribs = {
		itemTemplate: "allData/generalListItem",
		swipeToDelete: false
	};
    this.dateListModel = {           
		items: this.dateList
    };
	this.controller.setupWidget( 'dateList' , this.dateListAttribs, this.dateListModel);
*/
	
	//Activity drawer and list
	this.controller.setupWidget("activityDrawer",
		this.activityAttributes = {
			modelProperty: 'open',
			unstyled: true
		},
		this.activityModel = {
			open: false
		}
	);
	this.activityDrawer = this.controller.get("activityDrawer");
	this.controller.listen(this.controller.get("activityGroup"),Mojo.Event.tap,this.toggleActivityDrawer.bindAsEventListener(this));
	
	this.activityListAttribs = {
		itemTemplate: "allData/generalListItem",
		swipeToDelete: false
	};
    this.activityListModel = {           
		items: this.activityList
    };
	this.controller.setupWidget( 'activityList' , this.activityListAttribs, this.activityListModel);
	
	//device drawer and list
	this.controller.setupWidget("deviceDrawer",
		this.deviceAttributes = {
			modelProperty: 'open',
			unstyled: true
		},
		this.deviceModel = {
			open: false
		}
	);
	this.deviceDrawer = this.controller.get("deviceDrawer");
	this.controller.listen(this.controller.get("deviceGroup"),Mojo.Event.tap,this.toggleDeviceDrawer.bindAsEventListener(this));
	
	this.deviceListAttribs = {
		itemTemplate: "allData/generalListItem",
		swipeToDelete: false
	};
    this.deviceListModel = {           
		items: this.deviceList
    };
	this.controller.setupWidget( 'deviceList' , this.deviceListAttribs, this.deviceListModel);
	
	//carrier drawer and list
	this.controller.setupWidget("carrierDrawer",
		this.carrierAttributes = {
			modelProperty: 'open',
			unstyled: true
		},
		this.carrierModel = {
			open: false
		}
	);
	this.carrierDrawer = this.controller.get("carrierDrawer");
	this.controller.listen(this.controller.get("carrierGroup"),Mojo.Event.tap,this.toggleCarrierDrawer.bindAsEventListener(this));
	
	this.carrierListAttribs = {
		itemTemplate: "allData/generalListItem",
		swipeToDelete: false
	};
    this.carrierListModel = {           
		items: this.carrierList
    };
	this.controller.setupWidget( 'carrierList' , this.carrierListAttribs, this.carrierListModel);
	
	//resolution drawer and list
	this.controller.setupWidget("resolutionDrawer",
		this.resolutionAttributes = {
			modelProperty: 'open',
			unstyled: true
		},
		this.resolutionModel = {
			open: false
		}
	);
	this.resolutionDrawer = this.controller.get("resolutionDrawer");
	this.controller.listen(this.controller.get("resolutionGroup"),Mojo.Event.tap,this.toggleResolutionDrawer.bindAsEventListener(this));
	
	this.resolutionListAttribs = {
		itemTemplate: "allData/generalListItem",
		swipeToDelete: false
	};
    this.resolutionListModel = {           
		items: this.resolutionList
    };
	this.controller.setupWidget( 'resolutionList' , this.resolutionListAttribs, this.resolutionListModel);
	
	//locale drawer and list
	this.controller.setupWidget("localeDrawer",
		this.localeAttributes = {
			modelProperty: 'open',
			unstyled: true
		},
		this.localeModel = {
			open: false
		}
	);
	this.localeDrawer = this.controller.get("localeDrawer");
	this.controller.listen(this.controller.get("localeGroup"),Mojo.Event.tap,this.toggleLocaleDrawer.bindAsEventListener(this));
	
	this.localeListAttribs = {
		itemTemplate: "allData/generalListItem",
		swipeToDelete: false
	};
    this.localeListModel = {           
		items: this.localeList
    };
	this.controller.setupWidget( 'localeList' , this.localeListAttribs, this.localeListModel);
	
	//appVersion drawer and list
	this.controller.setupWidget("appVersionDrawer",
		this.appVersionAttributes = {
			modelProperty: 'open',
			unstyled: true
		},
		this.appVersionModel = {
			open: false
		}
	);
	this.appVersionDrawer = this.controller.get("appVersionDrawer");
	this.controller.listen(this.controller.get("appVersionGroup"),Mojo.Event.tap,this.toggleAppVersionDrawer.bindAsEventListener(this));
	
	this.appVersionListAttribs = {
		itemTemplate: "allData/generalListItem",
		swipeToDelete: false
	};
    this.appVersionListModel = {           
		items: this.appVersionList
    };
	this.controller.setupWidget( 'appVersionList' , this.appVersionListAttribs, this.appVersionListModel);
	
	//webosBuild drawer and list
	this.controller.setupWidget("webosBuildDrawer",
		this.webosBuildAttributes = {
			modelProperty: 'open',
			unstyled: true
		},
		this.webosBuildModel = {
			open: false
		}
	);
	this.webosBuildDrawer = this.controller.get("webosBuildDrawer");
	this.controller.listen(this.controller.get("webosBuildGroup"),Mojo.Event.tap,this.toggleWebosBuildDrawer.bindAsEventListener(this));
	
	this.webosBuildListAttribs = {
		itemTemplate: "allData/generalListItem",
		swipeToDelete: false
	};
    this.webosBuildListModel = {           
		items: this.webosBuildList
    };
	this.controller.setupWidget( 'webosBuildList' , this.webosBuildListAttribs, this.webosBuildListModel);
	
	//webosVersion drawer and list
	this.controller.setupWidget("webosVersionDrawer",
		this.webosVersionAttributes = {
			modelProperty: 'open',
			unstyled: true
		},
		this.webosVersionModel = {
			open: false
		}
	);
	this.webosVersionDrawer = this.controller.get("webosVersionDrawer");
	this.controller.listen(this.controller.get("webosVersionGroup"),Mojo.Event.tap,this.toggleWebosVersionDrawer.bindAsEventListener(this));
	
	this.webosVersionListAttribs = {
		itemTemplate: "allData/generalListItem",
		swipeToDelete: false
	};
    this.webosVersionListModel = {           
		items: this.webosVersionList
    };
	this.controller.setupWidget( 'webosVersionList' , this.webosVersionListAttribs, this.webosVersionListModel);
	
	
	
	//custom1 drawer and list
	this.controller.setupWidget("custom1Drawer",
		this.custom1Attributes = {
			modelProperty: 'open',
			unstyled: true
		},
		this.custom1Model = {
			open: false
		}
	);
	this.custom1Drawer = this.controller.get("custom1Drawer");
	this.controller.listen(this.controller.get("custom1Group"),Mojo.Event.tap,this.toggleCustom1Drawer.bindAsEventListener(this));
	
	this.custom1ListAttribs = {
		itemTemplate: "allData/generalListItem",
		swipeToDelete: false
	};
    this.custom1ListModel = {           
		items: this.custom1List
    };
	this.controller.setupWidget( 'custom1List' , this.custom1ListAttribs, this.custom1ListModel);
	
	//custom2 drawer and list
	this.controller.setupWidget("custom2Drawer",
		this.custom2Attributes = {
			modelProperty: 'open',
			unstyled: true
		},
		this.custom2Model = {
			open: false
		}
	);
	this.custom2Drawer = this.controller.get("custom2Drawer");
	this.controller.listen(this.controller.get("custom2Group"),Mojo.Event.tap,this.toggleCustom2Drawer.bindAsEventListener(this));
	
	this.custom2ListAttribs = {
		itemTemplate: "allData/generalListItem",
		swipeToDelete: false
	};
    this.custom2ListModel = {           
		items: this.custom2List
    };
	this.controller.setupWidget( 'custom2List' , this.custom2ListAttribs, this.custom2ListModel);
	
	//custom3 drawer and list
	this.controller.setupWidget("custom3Drawer",
		this.custom3Attributes = {
			modelProperty: 'open',
			unstyled: true
		},
		this.custom3Model = {
			open: false
		}
	);
	this.custom3Drawer = this.controller.get("custom3Drawer");
	this.controller.listen(this.controller.get("custom3Group"),Mojo.Event.tap,this.toggleCustom3Drawer.bindAsEventListener(this));
	
	this.custom3ListAttribs = {
		itemTemplate: "allData/generalListItem",
		swipeToDelete: false
	};
    this.custom3ListModel = {           
		items: this.custom3List
    };
	this.controller.setupWidget( 'custom3List' , this.custom3ListAttribs, this.custom3ListModel);
	
	//custom4 drawer and list
	this.controller.setupWidget("custom4Drawer",
		this.custom4Attributes = {
			modelProperty: 'open',
			unstyled: true
		},
		this.custom4Model = {
			open: false
		}
	);
	this.custom4Drawer = this.controller.get("custom4Drawer");
	this.controller.listen(this.controller.get("custom4Group"),Mojo.Event.tap,this.toggleCustom4Drawer.bindAsEventListener(this));
	
	this.custom4ListAttribs = {
		itemTemplate: "allData/generalListItem",
		swipeToDelete: false
	};
    this.custom4ListModel = {           
		items: this.custom4List
    };
	this.controller.setupWidget( 'custom4List' , this.custom4ListAttribs, this.custom4ListModel);
	
	
	
	

	$('scene-title').innerText = MetrixViewer.appname;
	
	this.controller.listen(this.controller.get( "header-menu" ), Mojo.Event.tap, this.tapHeader.bind(this));
	
	this.getData();

};

AllDataAssistant.prototype.activate = function(event) {

	this.getCustom();

};

AllDataAssistant.prototype.deactivate = function(event) {

};

AllDataAssistant.prototype.cleanup = function(event) {

};

AllDataAssistant.prototype.handleCommand = function(event) {

	if(event.type == Mojo.Event.command) {
		Mojo.Log.info("Command: "+event.command);

		switch(event.command) {
			case 'do-launch':
				
				this.controller.serviceRequest("palm://com.palm.applicationManager", {
					method: "open",
					parameters:  {
						id: MetrixViewer.packageId,
						params: {
						
						}
					}
				});
			  break;
			  
			case 'do-refresh':
				this.getData();
				this.getCustom();
				
			  break;
			  
			case 'do-custom':
				Mojo.Controller.stageController.pushScene("editCustom");
			  break;
			  
			case 'do-catalog':
				
				this.controller.serviceRequest("palm://com.palm.applicationManager", {
					method: "open",
					parameters:  {
						id: 'com.palm.app.findapps',
						params: {
							scene: 'page',
							target: "http://developer.palm.com/appredirect/?packageid="+MetrixViewer.packageId
						}
					}
				});
				
			  break;

		}
		
	}
	
}




AllDataAssistant.prototype.toggleDateDrawer = function() {

	this.dateDrawer.mojo.setOpenState(!this.dateDrawer.mojo.getOpenState());

	if (this.dateDrawer.mojo.getOpenState() == true){
		this.controller.get("dateArrow").removeClassName("palm-arrow-closed").addClassName("palm-arrow-expanded")
	} else {
		this.controller.get("dateArrow").removeClassName("palm-arrow-expanded").addClassName("palm-arrow-closed")
	}
	
};

AllDataAssistant.prototype.toggleActivityDrawer = function() {

	this.activityDrawer.mojo.setOpenState(!this.activityDrawer.mojo.getOpenState());

	if (this.activityDrawer.mojo.getOpenState() == true){
		this.controller.get("activityArrow").removeClassName("palm-arrow-closed").addClassName("palm-arrow-expanded")
	} else {
		this.controller.get("activityArrow").removeClassName("palm-arrow-expanded").addClassName("palm-arrow-closed")
	}
	
};

AllDataAssistant.prototype.toggleDeviceDrawer = function() {

	this.deviceDrawer.mojo.setOpenState(!this.deviceDrawer.mojo.getOpenState());

	if (this.deviceDrawer.mojo.getOpenState() == true){
		this.controller.get("deviceArrow").removeClassName("palm-arrow-closed").addClassName("palm-arrow-expanded")
	} else {
		this.controller.get("deviceArrow").removeClassName("palm-arrow-expanded").addClassName("palm-arrow-closed")
	}
	
};

AllDataAssistant.prototype.toggleCarrierDrawer = function() {

	this.carrierDrawer.mojo.setOpenState(!this.carrierDrawer.mojo.getOpenState());
	
	if (this.carrierDrawer.mojo.getOpenState() == true){
		this.controller.get("carrierArrow").removeClassName("palm-arrow-closed").addClassName("palm-arrow-expanded")
	} else {
		this.controller.get("carrierArrow").removeClassName("palm-arrow-expanded").addClassName("palm-arrow-closed")
	}
	
};

AllDataAssistant.prototype.toggleResolutionDrawer = function() {

	this.resolutionDrawer.mojo.setOpenState(!this.resolutionDrawer.mojo.getOpenState());

	if (this.resolutionDrawer.mojo.getOpenState() == true){
		this.controller.get("resolutionArrow").removeClassName("palm-arrow-closed").addClassName("palm-arrow-expanded")
	} else {
		this.controller.get("resolutionArrow").removeClassName("palm-arrow-expanded").addClassName("palm-arrow-closed")
	}
	
};

AllDataAssistant.prototype.toggleLocaleDrawer = function() {

	this.localeDrawer.mojo.setOpenState(!this.localeDrawer.mojo.getOpenState());
	
	if (this.localeDrawer.mojo.getOpenState() == true){
		this.controller.get("localeArrow").removeClassName("palm-arrow-closed").addClassName("palm-arrow-expanded")
	} else {
		this.controller.get("localeArrow").removeClassName("palm-arrow-expanded").addClassName("palm-arrow-closed")
	}
	
};

AllDataAssistant.prototype.toggleAppVersionDrawer = function() {

	this.appVersionDrawer.mojo.setOpenState(!this.appVersionDrawer.mojo.getOpenState());

	if (this.appVersionDrawer.mojo.getOpenState() == true){
		this.controller.get("appVersionArrow").removeClassName("palm-arrow-closed").addClassName("palm-arrow-expanded")
	} else {
		this.controller.get("appVersionArrow").removeClassName("palm-arrow-expanded").addClassName("palm-arrow-closed")
	}
	
};

AllDataAssistant.prototype.toggleWebosBuildDrawer = function() {

	this.webosBuildDrawer.mojo.setOpenState(!this.webosBuildDrawer.mojo.getOpenState());

	if (this.webosBuildDrawer.mojo.getOpenState() == true){
		this.controller.get("webosBuildArrow").removeClassName("palm-arrow-closed").addClassName("palm-arrow-expanded")
	} else {
		this.controller.get("webosBuildArrow").removeClassName("palm-arrow-expanded").addClassName("palm-arrow-closed")
	}
	
};

AllDataAssistant.prototype.toggleWebosVersionDrawer = function() {

	this.webosVersionDrawer.mojo.setOpenState(!this.webosVersionDrawer.mojo.getOpenState());

	if (this.webosVersionDrawer.mojo.getOpenState() == true){
		this.controller.get("webosVersionArrow").removeClassName("palm-arrow-closed").addClassName("palm-arrow-expanded")
	} else {
		this.controller.get("webosVersionArrow").removeClassName("palm-arrow-expanded").addClassName("palm-arrow-closed")
	}
	
};

AllDataAssistant.prototype.toggleCustom1Drawer = function() {

	this.custom1Drawer.mojo.setOpenState(!this.custom1Drawer.mojo.getOpenState());

	if (this.custom1Drawer.mojo.getOpenState() == true){
		this.controller.get("custom1Arrow").removeClassName("palm-arrow-closed").addClassName("palm-arrow-expanded")
	} else {
		this.controller.get("custom1Arrow").removeClassName("palm-arrow-expanded").addClassName("palm-arrow-closed")
	}
	
};

AllDataAssistant.prototype.toggleCustom2Drawer = function() {

	this.custom2Drawer.mojo.setOpenState(!this.custom2Drawer.mojo.getOpenState());

	if (this.custom2Drawer.mojo.getOpenState() == true){
		this.controller.get("custom2Arrow").removeClassName("palm-arrow-closed").addClassName("palm-arrow-expanded")
	} else {
		this.controller.get("custom2Arrow").removeClassName("palm-arrow-expanded").addClassName("palm-arrow-closed")
	}
	
};

AllDataAssistant.prototype.toggleCustom3Drawer = function() {

	this.custom3Drawer.mojo.setOpenState(!this.custom3Drawer.mojo.getOpenState());

	if (this.custom3Drawer.mojo.getOpenState() == true){
		this.controller.get("custom3Arrow").removeClassName("palm-arrow-closed").addClassName("palm-arrow-expanded")
	} else {
		this.controller.get("custom3Arrow").removeClassName("palm-arrow-expanded").addClassName("palm-arrow-closed")
	}
	
};

AllDataAssistant.prototype.toggleCustom4Drawer = function() {

	this.custom4Drawer.mojo.setOpenState(!this.custom4Drawer.mojo.getOpenState());

	if (this.custom4Drawer.mojo.getOpenState() == true){
		this.controller.get("custom4Arrow").removeClassName("palm-arrow-closed").addClassName("palm-arrow-expanded")
	} else {
		this.controller.get("custom4Arrow").removeClassName("palm-arrow-expanded").addClassName("palm-arrow-closed")
	}
	
};




AllDataAssistant.prototype.tapHeader = function() {

	this.controller.sceneScroller.mojo.revealTop();

}	
	
AllDataAssistant.prototype.getData = function() {

	var activityRequestUrl = "http://metrix.webosroundup.com/MetrixInterface.asmx/GetCurrentActivityBreakDown?packageId="+MetrixViewer.packageId;
	var request = new Ajax.Request(activityRequestUrl,{
		method: 'get',
		evalJSON: false,
		onSuccess: this.readActivitySuccess.bind(this),
		onFailure: this.readMetrixFail.bind(this)  
	});
	

	var deviceRequestUrl = "http://metrix.webosroundup.com/MetrixInterface.asmx/GetDeviceNameBreakDown?packageId="+MetrixViewer.packageId;
	var request = new Ajax.Request(deviceRequestUrl,{
		method: 'get',
		evalJSON: false,
		onSuccess: this.readDeviceSuccess.bind(this),
		onFailure: this.readMetrixFail.bind(this)  
	});
	

	var carrierRequestUrl = "http://metrix.webosroundup.com/MetrixInterface.asmx/GetCarrierBreakDown?packageId="+MetrixViewer.packageId;
	var request = new Ajax.Request(carrierRequestUrl,{
		method: 'get',
		evalJSON: false,
		onSuccess: this.readCarrierSuccess.bind(this),
		onFailure: this.readMetrixFail.bind(this)  
	});
	

	var resolutionRequestUrl = "http://metrix.webosroundup.com/MetrixInterface.asmx/GetScreenResolutionBreakDown?packageId="+MetrixViewer.packageId;	
	var request = new Ajax.Request(resolutionRequestUrl,{
		method: 'get',
		evalJSON: false,
		onSuccess: this.readResolutionSuccess.bind(this),
		onFailure: this.readMetrixFail.bind(this)  
	});
	

	var localeRequestUrl = "http://metrix.webosroundup.com/MetrixInterface.asmx/GetLocaleBreakDown?packageId="+MetrixViewer.packageId;	
	var request = new Ajax.Request(localeRequestUrl,{
		method: 'get',
		evalJSON: false,
		onSuccess: this.readLocaleSuccess.bind(this),
		onFailure: this.readMetrixFail.bind(this)  
	});
	

	var appVersionRequestUrl = "http://metrix.webosroundup.com/MetrixInterface.asmx/GetVersionBreakDown?packageId="+MetrixViewer.packageId;
	var request = new Ajax.Request(appVersionRequestUrl,{
		method: 'get',
		evalJSON: false,
		onSuccess: this.readAppVersionSuccess.bind(this),
		onFailure: this.readMetrixFail.bind(this)  
	});
	

	var buildRequestUrl = "http://metrix.webosroundup.com/MetrixInterface.asmx/GetWebOsBuildNumberBreakDown?packageId="+MetrixViewer.packageId;
	var request = new Ajax.Request(buildRequestUrl,{
		method: 'get',
		evalJSON: false,
		onSuccess: this.readWebosBuildSuccess.bind(this),
		onFailure: this.readMetrixFail.bind(this)  
	});
	

	var webosVersionRequestUrl = "http://metrix.webosroundup.com/MetrixInterface.asmx/GetWebOsVersionBreakDown?packageId="+MetrixViewer.packageId;
	var request = new Ajax.Request(webosVersionRequestUrl,{
		method: 'get',
		evalJSON: false,
		onSuccess: this.readWebosVersionSuccess.bind(this),
		onFailure: this.readMetrixFail.bind(this)  
	});
	

};

AllDataAssistant.prototype.getCustom = function() {

	//If we have get custom metrics, otherwise hide
	if(getCustomMetric(MetrixViewer.customCookieObject,MetrixViewer.packageId,1) == "") {
		$('custom1wrapper').hide();
	} else {
		$('custom1wrapper').show();	
		
		$('custom1Divider-label').innerText = getCustomMetric(MetrixViewer.customCookieObject,MetrixViewer.packageId,1);
			
		var custom1RequestUrl = "http://metrix.webosroundup.com/MetrixInterface.asmx/getCustomCounterAsBar?packageId="+MetrixViewer.packageId;
		custom1RequestUrl += "&valueGroup="+getCustomMetric(MetrixViewer.customCookieObject,MetrixViewer.packageId,1);
		var request = new Ajax.Request(custom1RequestUrl,{
			method: 'get',
			evalJSON: false,
			onSuccess: this.readCustom1Success.bind(this),
			onFailure: this.readMetrixFail.bind(this)  
		});
		
	}
	
	if(getCustomMetric(MetrixViewer.customCookieObject,MetrixViewer.packageId,2) == "") {
		$('custom2wrapper').hide();
	} else {
		$('custom2wrapper').show();	
		
		$('custom2Divider-label').innerText = getCustomMetric(MetrixViewer.customCookieObject,MetrixViewer.packageId,2);
			
		var custom1RequestUrl = "http://metrix.webosroundup.com/MetrixInterface.asmx/getCustomCounterAsBar?packageId="+MetrixViewer.packageId;
		custom1RequestUrl += "&valueGroup="+getCustomMetric(MetrixViewer.customCookieObject,MetrixViewer.packageId,2);
		var request = new Ajax.Request(custom1RequestUrl,{
			method: 'get',
			evalJSON: false,
			onSuccess: this.readCustom2Success.bind(this),
			onFailure: this.readMetrixFail.bind(this)  
		});
		
	}
	
	if(getCustomMetric(MetrixViewer.customCookieObject,MetrixViewer.packageId,3) == "") {
		$('custom3wrapper').hide();
	} else {
		$('custom3wrapper').show();	
		
		$('custom3Divider-label').innerText = getCustomMetric(MetrixViewer.customCookieObject,MetrixViewer.packageId,3);
			
		var custom1RequestUrl = "http://metrix.webosroundup.com/MetrixInterface.asmx/getCustomCounterAsBar?packageId="+MetrixViewer.packageId;
		custom1RequestUrl += "&valueGroup="+getCustomMetric(MetrixViewer.customCookieObject,MetrixViewer.packageId,3);
		var request = new Ajax.Request(custom1RequestUrl,{
			method: 'get',
			evalJSON: false,
			onSuccess: this.readCustom3Success.bind(this),
			onFailure: this.readMetrixFail.bind(this)  
		});
		
	}
	
	if(getCustomMetric(MetrixViewer.customCookieObject,MetrixViewer.packageId,4) == "") {
		$('custom4wrapper').hide();
	} else {
		$('custom4wrapper').show();	
		
		$('custom4Divider-label').innerText = getCustomMetric(MetrixViewer.customCookieObject,MetrixViewer.packageId,4);
			
		var custom1RequestUrl = "http://metrix.webosroundup.com/MetrixInterface.asmx/getCustomCounterAsBar?packageId="+MetrixViewer.packageId;
		custom1RequestUrl += "&valueGroup="+getCustomMetric(MetrixViewer.customCookieObject,MetrixViewer.packageId,4);
		var request = new Ajax.Request(custom1RequestUrl,{
			method: 'get',
			evalJSON: false,
			onSuccess: this.readCustom4Success.bind(this),
			onFailure: this.readMetrixFail.bind(this)  
		});
		
	}
	
}

AllDataAssistant.prototype.readMetrixFail = function(response) {

	Mojo.Log.error("Error getting Metrix data");
	
	Mojo.Controller.errorDialog("Error getting data from Metrix.  Check your packageId.");

};

AllDataAssistant.prototype.readActivitySuccess = function(response) {

	//Mojo.Log.info("Activity response: "+response.responseText.trim());
	
	this.activityList.clear();
	this.totalCount = 0;
	
	var xmlobject = (new DOMParser()).parseFromString(response.responseText.trim(), "text/xml");
	
	var s = {};
	var sliceValues = "", sliceLabels = "";
	
	
	var slicesArray = xmlobject.getElementsByTagName("slice");
	
	//Mojo.Log.info("Found "+slicesArray.length+" slices in XML response");
	
	for(var i = 0; i < slicesArray.length; i++) {
	
		s = {};
	
		s.label = slicesArray[i].getAttributeNode("title").nodeValue;
		s.title = parseInt(slicesArray[i].childNodes[0].nodeValue);
		
		this.totalCount = this.totalCount + parseInt(slicesArray[i].childNodes[0].nodeValue);
		
		if(i == 0) {
			sliceValues += parseInt(s.title);
			sliceLabels += s.label.replace(" ","_").replace(" ","_").replace(" ","_").replace(" ","_").replace(" ","_");
		} else {
			sliceValues += ","+parseInt(s.title);
			sliceLabels += "|"+s.label.replace(" ","_").replace(" ","_").replace(" ","_").replace(" ","_").replace(" ","_");
		}
		
		//Mojo.Log.info("Adding activity data: %j",s);
		
		this.activityList.push(s);
	
	}
	
	//Mojo.Log.info("Final activity list: %j",this.activityList);
	
	this.controller.modelChanged(this.activityListModel);
	
	
	
	var activityChartUrl = "https://chart.googleapis.com/chart?";
	activityChartUrl += "cht=p&amp;";
	activityChartUrl += "chs=310x160&amp;";
	activityChartUrl += "chp=4.712&amp;";
	activityChartUrl += "chco=00FF00,FF0033&amp;";
	activityChartUrl += "chd=t:"+sliceValues+"&amp;";
	activityChartUrl += "chdl="+sliceLabels;
	
	//Mojo.Log.info("Activity chart URL: "+activityChartUrl);
	
	$('activityChart').innerHTML = "<img src="+activityChartUrl+" />";
	
	$('scene-title').innerText = MetrixViewer.appname + " ("+this.totalCount+")";
	
}

AllDataAssistant.prototype.readDeviceSuccess = function(response) {

	//Mojo.Log.info("Device response: "+response.responseText.trim());
	
	this.deviceList.clear();
	
	var xmlobject = (new DOMParser()).parseFromString(response.responseText.trim(), "text/xml");
	
	var dataValues = "", dataLabels = "", maxValue = 1;
	
	
	var seriesNode = xmlobject.getElementsByTagName("series")[0];
	var seriesData = [];
	
	for(var i = 0; i < seriesNode.childNodes.length; i++){
	
		if(seriesNode.childNodes[i].nodeName == 'value'){
		
			seriesData.push( {"xid": seriesNode.childNodes[i].getAttributeNode("xid").nodeValue, "name": seriesNode.childNodes[i].childNodes[0].nodeValue} );
				
			if(dataLabels == "") {
				dataLabels = seriesNode.childNodes[i].childNodes[0].nodeValue;
			} else {
				dataLabels += "|"+seriesNode.childNodes[i].childNodes[0].nodeValue;
			}
		}
	
	}
	
	
	var graphNode = xmlobject.getElementsByTagName("graph")[0];
	var graphData = [];
	
	for(var j = 0; j < graphNode.childNodes.length; j++){
	
		if(graphNode.childNodes[j].nodeName == 'value'){
		
			graphData.push({"xid": graphNode.childNodes[j].getAttributeNode("xid").nodeValue, "value": graphNode.childNodes[j].childNodes[0].nodeValue});
			
			maxValue = Math.max(maxValue,parseInt(graphNode.childNodes[j].childNodes[0].nodeValue));
			
			if(dataValues == "") {
				dataValues = graphNode.childNodes[j].childNodes[0].nodeValue;
			} else {
				dataValues += ","+graphNode.childNodes[j].childNodes[0].nodeValue;
			}
				
		}
	
	}
	
	
	for(var k = 0; k < seriesData.length; k++){
	
		for(var l = 0; l < graphData.length; l++){
		
			if(seriesData[k].xid == graphData[l].xid) {
			
				this.deviceList.push({"label": seriesData[k].name, "title": graphData[l].value});
			
			}
		}
	}	
	
	//Mojo.Log.info("Final device list: %j",this.deviceList);
	
	this.controller.modelChanged(this.deviceListModel);
	
	
	var deviceChartUrl = "https://chart.googleapis.com/chart?";
	deviceChartUrl += "cht=bvs&amp;";
	deviceChartUrl += "chs=310x160&amp;";
	deviceChartUrl += "chco=4D89F9&amp;";
	deviceChartUrl += "chd=t:"+dataValues+"&amp;";
	deviceChartUrl += "chdl="+dataLabels+"&amp;";
	deviceChartUrl += "chds=0,"+parseInt((maxValue+1)*1.1);
	
	//Mojo.Log.info("Device chart URL: "+deviceChartUrl);
	
	$('deviceChart').innerHTML = "<img src="+deviceChartUrl+" />";

}

AllDataAssistant.prototype.readCarrierSuccess = function(response) {

	//Mojo.Log.info("Carrier response: "+response.responseText.trim());
	
	this.carrierList.clear();
	
	var xmlobject = (new DOMParser()).parseFromString(response.responseText.trim(), "text/xml");	
	
	var dataValues = "", dataLabels = "", maxValue = 1;
	
	var seriesNode = xmlobject.getElementsByTagName("series")[0];
	var seriesData = [];
	
	for(var i = 0; i < seriesNode.childNodes.length; i++){
	
		if(seriesNode.childNodes[i].nodeName == 'value'){
		
			seriesData.push( {"xid": seriesNode.childNodes[i].getAttributeNode("xid").nodeValue, "name": seriesNode.childNodes[i].childNodes[0].nodeValue} );
				
			if(dataLabels == "") {
				dataLabels = seriesNode.childNodes[i].childNodes[0].nodeValue.replace(" ","_").replace(" ","_").replace(" ","_").replace(" ","_");
			} else {
				dataLabels += "|"+seriesNode.childNodes[i].childNodes[0].nodeValue.replace(" ","_").replace(" ","_").replace(" ","_").replace(" ","_");
			}
				
		}
	
	}
	
	
	var graphNode = xmlobject.getElementsByTagName("graph")[0];
	var graphData = [];
	
	for(var j = 0; j < graphNode.childNodes.length; j++){
	
		if(graphNode.childNodes[j].nodeName == 'value'){
		
			graphData.push({"xid": graphNode.childNodes[j].getAttributeNode("xid").nodeValue, "value": graphNode.childNodes[j].childNodes[0].nodeValue});
			
			maxValue = Math.max(maxValue,parseInt(graphNode.childNodes[j].childNodes[0].nodeValue));
			
			if(dataValues == "") {
				dataValues = graphNode.childNodes[j].childNodes[0].nodeValue.replace(" ","_").replace(" ","_").replace(" ","_").replace(" ","_");
			} else {
				dataValues += ","+graphNode.childNodes[j].childNodes[0].nodeValue.replace(" ","_").replace(" ","_").replace(" ","_").replace(" ","_");
			}
		
		}
	
	}
	
	
	for(var k = 0; k < seriesData.length; k++){
	
		for(var l = 0; l < graphData.length; l++){
		
			if(seriesData[k].xid == graphData[l].xid) {
			
				this.carrierList.push({"label": seriesData[k].name, "title": graphData[l].value});
			
			}
		}
	}	
	
	//Mojo.Log.info("Final carrier list: %j",this.carrierList);
	
	this.controller.modelChanged(this.carrierListModel);
	
	
	var carrierChartUrl = "https://chart.googleapis.com/chart?";
	carrierChartUrl += "cht=bvs&amp;";
	carrierChartUrl += "chs=310x160&amp;";
	carrierChartUrl += "chco=4D89F9&amp;";
	carrierChartUrl += "chd=t:"+dataValues+"&amp;";
	carrierChartUrl += "chdl="+dataLabels+"&amp;";
	carrierChartUrl += "chds=0,"+parseInt((maxValue+1)*1.1);
	
	//Mojo.Log.info("Carrier chart URL: "+carrierChartUrl);
	
	$('carrierChart').innerHTML = "<img src="+carrierChartUrl+" />";

}

AllDataAssistant.prototype.readResolutionSuccess = function(response) {

	//Mojo.Log.info("Resolution response: "+response.responseText.trim());
	
	this.resolutionList.clear();
	
	var xmlobject = (new DOMParser()).parseFromString(response.responseText.trim(), "text/xml");	
	
	var dataValues = "", dataLabels = "", maxValue = 1;
	
	var seriesNode = xmlobject.getElementsByTagName("series")[0];
	var seriesData = [];
	
	for(var i = 0; i < seriesNode.childNodes.length; i++){
	
		if(seriesNode.childNodes[i].nodeName == 'value'){
		
			seriesData.push( {"xid": seriesNode.childNodes[i].getAttributeNode("xid").nodeValue, "name": seriesNode.childNodes[i].childNodes[0].nodeValue} );
				
			if(dataLabels == "") {
				dataLabels = seriesNode.childNodes[i].childNodes[0].nodeValue.replace(" ","_").replace(" ","_").replace(" ","_").replace(" ","_");
			} else {
				dataLabels += "|"+seriesNode.childNodes[i].childNodes[0].nodeValue.replace(" ","_").replace(" ","_").replace(" ","_").replace(" ","_");
			}
				
		}
	
	}
	
	
	var graphNode = xmlobject.getElementsByTagName("graph")[0];
	var graphData = [];
	
	for(var j = 0; j < graphNode.childNodes.length; j++){
	
		if(graphNode.childNodes[j].nodeName == 'value'){
		
			graphData.push({"xid": graphNode.childNodes[j].getAttributeNode("xid").nodeValue, "value": graphNode.childNodes[j].childNodes[0].nodeValue});
			
			maxValue = Math.max(maxValue,parseInt(graphNode.childNodes[j].childNodes[0].nodeValue));
			
			if(dataValues == "") {
				dataValues = graphNode.childNodes[j].childNodes[0].nodeValue.replace(" ","_").replace(" ","_").replace(" ","_").replace(" ","_");
			} else {
				dataValues += ","+graphNode.childNodes[j].childNodes[0].nodeValue.replace(" ","_").replace(" ","_").replace(" ","_").replace(" ","_");
			}
		
		}
	
	}
	
	
	for(var k = 0; k < seriesData.length; k++){
	
		for(var l = 0; l < graphData.length; l++){
		
			if(seriesData[k].xid == graphData[l].xid) {
			
				this.resolutionList.push({"label": seriesData[k].name, "title": graphData[l].value});
			
			}
		}
	}	
	
	//Mojo.Log.info("Final carrier list: %j",this.carrierList);
	
	this.controller.modelChanged(this.resolutionListModel);
	
	
	var resolutionChartUrl = "https://chart.googleapis.com/chart?";
	resolutionChartUrl += "cht=bvs&amp;";
	resolutionChartUrl += "chs=310x160&amp;";
	resolutionChartUrl += "chco=4D89F9&amp;";
	resolutionChartUrl += "chd=t:"+dataValues+"&amp;";
	resolutionChartUrl += "chdl="+dataLabels+"&amp;";
	resolutionChartUrl += "chds=0,"+parseInt((maxValue+1)*1.1);
	
	//Mojo.Log.info("Resolution chart URL: "+resolutionChartUrl);
	
	$('resolutionChart').innerHTML = "<img src="+resolutionChartUrl+" />";
}

AllDataAssistant.prototype.readLocaleSuccess = function(response) {

	//Mojo.Log.info("Locale response: "+response.responseText.trim());
	
	this.localeList.clear();
	
	var xmlobject = (new DOMParser()).parseFromString(response.responseText.trim(), "text/xml");	
	
	var dataValues = "", dataLabels = "", maxValue = 1;
	
	var seriesNode = xmlobject.getElementsByTagName("series")[0];
	var seriesData = [];
	
	for(var i = 0; i < seriesNode.childNodes.length; i++){
	
		if(seriesNode.childNodes[i].nodeName == 'value'){
		
			seriesData.push( {"xid": seriesNode.childNodes[i].getAttributeNode("xid").nodeValue, "name": seriesNode.childNodes[i].childNodes[0].nodeValue} );
				
			if(dataLabels == "") {
				dataLabels = seriesNode.childNodes[i].childNodes[0].nodeValue.replace(" ","_").replace(" ","_").replace(" ","_").replace(" ","_");
			} else {
				dataLabels += "|"+seriesNode.childNodes[i].childNodes[0].nodeValue.replace(" ","_").replace(" ","_").replace(" ","_").replace(" ","_");
			}
				
		}
	
	}
	
	
	var graphNode = xmlobject.getElementsByTagName("graph")[0];
	var graphData = [];
	
	for(var j = 0; j < graphNode.childNodes.length; j++){
	
		if(graphNode.childNodes[j].nodeName == 'value'){
		
			graphData.push({"xid": graphNode.childNodes[j].getAttributeNode("xid").nodeValue, "value": graphNode.childNodes[j].childNodes[0].nodeValue});
			
			maxValue = Math.max(maxValue,parseInt(graphNode.childNodes[j].childNodes[0].nodeValue));
			
			if(dataValues == "") {
				dataValues = graphNode.childNodes[j].childNodes[0].nodeValue.replace(" ","_").replace(" ","_").replace(" ","_").replace(" ","_");
			} else {
				dataValues += ","+graphNode.childNodes[j].childNodes[0].nodeValue.replace(" ","_").replace(" ","_").replace(" ","_").replace(" ","_");
			}
		
		}
	
	}
	
	
	for(var k = 0; k < seriesData.length; k++){
	
		for(var l = 0; l < graphData.length; l++){
		
			if(seriesData[k].xid == graphData[l].xid) {
			
				this.localeList.push({"label": seriesData[k].name, "title": graphData[l].value});
			
			}
		}
	}	
	
	//Mojo.Log.info("Final locale list: %j",this.localeList);
	
	this.controller.modelChanged(this.localeListModel);
	
	
	var localeChartUrl = "https://chart.googleapis.com/chart?";
	localeChartUrl += "cht=bvs&amp;";
	localeChartUrl += "chs=310x160&amp;";
	localeChartUrl += "chco=4D89F9&amp;";
	localeChartUrl += "chd=t:"+dataValues+"&amp;";
	localeChartUrl += "chdl="+dataLabels+"&amp;";
	localeChartUrl += "chds=0,"+parseInt((maxValue+1)*1.1);
	
	//Mojo.Log.info("locale chart URL: "+localeChartUrl);
	
	$('localeChart').innerHTML = "<img src="+localeChartUrl+" />";
	
}

AllDataAssistant.prototype.readAppVersionSuccess = function(response) {

	//Mojo.Log.info("App Version response: "+response.responseText.trim());
	
	this.appVersionList.clear();
	
	var xmlobject = (new DOMParser()).parseFromString(response.responseText.trim(), "text/xml");	
	
	var dataValues = "", dataLabels = "", maxValue = 1;
	
	var seriesNode = xmlobject.getElementsByTagName("series")[0];
	var seriesData = [];
	
	for(var i = 0; i < seriesNode.childNodes.length; i++){
	
		if(seriesNode.childNodes[i].nodeName == 'value'){
		
			seriesData.push( {"xid": seriesNode.childNodes[i].getAttributeNode("xid").nodeValue, "name": seriesNode.childNodes[i].childNodes[0].nodeValue} );
				
			if(dataLabels == "") {
				dataLabels = seriesNode.childNodes[i].childNodes[0].nodeValue.replace(" ","_").replace(" ","_").replace(" ","_").replace(" ","_");
			} else {
				dataLabels += "|"+seriesNode.childNodes[i].childNodes[0].nodeValue.replace(" ","_").replace(" ","_").replace(" ","_").replace(" ","_");
			}
				
		}
	
	}
	
	
	var graphNode = xmlobject.getElementsByTagName("graph")[0];
	var graphData = [];
	
	for(var j = 0; j < graphNode.childNodes.length; j++){
	
		if(graphNode.childNodes[j].nodeName == 'value'){
		
			graphData.push({"xid": graphNode.childNodes[j].getAttributeNode("xid").nodeValue, "value": graphNode.childNodes[j].childNodes[0].nodeValue});
			
			maxValue = Math.max(maxValue,parseInt(graphNode.childNodes[j].childNodes[0].nodeValue));
			
			if(dataValues == "") {
				dataValues = graphNode.childNodes[j].childNodes[0].nodeValue.replace(" ","_").replace(" ","_").replace(" ","_").replace(" ","_");
			} else {
				dataValues += ","+graphNode.childNodes[j].childNodes[0].nodeValue.replace(" ","_").replace(" ","_").replace(" ","_").replace(" ","_");
			}
		
		}
	
	}
	
	
	for(var k = 0; k < seriesData.length; k++){
	
		for(var l = 0; l < graphData.length; l++){
		
			if(seriesData[k].xid == graphData[l].xid) {
			
				this.appVersionList.push({"label": seriesData[k].name, "title": graphData[l].value});
			
			}
		}
	}	
	
	//Mojo.Log.info("Final appVersion list: %j",this.appVersionList);
	
	this.controller.modelChanged(this.appVersionListModel);
	
	
	var appVersionChartUrl = "https://chart.googleapis.com/chart?";
	appVersionChartUrl += "cht=bvs&amp;";
	appVersionChartUrl += "chs=310x160&amp;";
	appVersionChartUrl += "chco=4D89F9&amp;";
	appVersionChartUrl += "chd=t:"+dataValues+"&amp;";
	appVersionChartUrl += "chdl="+dataLabels+"&amp;";
	appVersionChartUrl += "chds=0,"+parseInt((maxValue+1)*1.1);
	
	//Mojo.Log.info("appVersionChartUrl chart URL: "+appVersionChartUrl);
	
	$('appVersionChart').innerHTML = "<img src="+appVersionChartUrl+" />";
	
}

AllDataAssistant.prototype.readWebosBuildSuccess = function(response) {

	//Mojo.Log.info("WebOS Build response: "+response.responseText.trim());
	
	this.webosBuildList.clear();
	
	var xmlobject = (new DOMParser()).parseFromString(response.responseText.trim(), "text/xml");	
	
	var dataValues = "", dataLabels = "", maxValue = 1;
	
	var seriesNode = xmlobject.getElementsByTagName("series")[0];
	var seriesData = [];
	
	for(var i = 0; i < seriesNode.childNodes.length; i++){
	
		if(seriesNode.childNodes[i].nodeName == 'value'){
		
			seriesData.push( {"xid": seriesNode.childNodes[i].getAttributeNode("xid").nodeValue, "name": seriesNode.childNodes[i].childNodes[0].nodeValue} );
				
			if(dataLabels == "") {
				dataLabels = seriesNode.childNodes[i].childNodes[0].nodeValue.replace(" ","_").replace(" ","_").replace(" ","_").replace(" ","_");
			} else {
				dataLabels += "|"+seriesNode.childNodes[i].childNodes[0].nodeValue.replace(" ","_").replace(" ","_").replace(" ","_").replace(" ","_");
			}
				
		}
	
	}
	
	
	var graphNode = xmlobject.getElementsByTagName("graph")[0];
	var graphData = [];
	
	for(var j = 0; j < graphNode.childNodes.length; j++){
	
		if(graphNode.childNodes[j].nodeName == 'value'){
		
			graphData.push({"xid": graphNode.childNodes[j].getAttributeNode("xid").nodeValue, "value": graphNode.childNodes[j].childNodes[0].nodeValue});
			
			maxValue = Math.max(maxValue,parseInt(graphNode.childNodes[j].childNodes[0].nodeValue));
			
			if(dataValues == "") {
				dataValues = graphNode.childNodes[j].childNodes[0].nodeValue.replace(" ","_").replace(" ","_").replace(" ","_").replace(" ","_");
			} else {
				dataValues += ","+graphNode.childNodes[j].childNodes[0].nodeValue.replace(" ","_").replace(" ","_").replace(" ","_").replace(" ","_");
			}
		
		}
	
	}
	
	
	for(var k = 0; k < seriesData.length; k++){
	
		for(var l = 0; l < graphData.length; l++){
		
			if(seriesData[k].xid == graphData[l].xid) {
			
				this.webosBuildList.push({"label": seriesData[k].name, "title": graphData[l].value});
			
			}
		}
	}	
	
	//Mojo.Log.info("Final webosBuildList list: %j",this.webosBuildList);
	
	this.controller.modelChanged(this.webosBuildListModel);
	
	
	var webosBuildChartUrl = "https://chart.googleapis.com/chart?";
	webosBuildChartUrl += "cht=bvs&amp;";
	webosBuildChartUrl += "chs=310x160&amp;";
	webosBuildChartUrl += "chco=4D89F9&amp;";
	webosBuildChartUrl += "chd=t:"+dataValues+"&amp;";
	webosBuildChartUrl += "chdl="+dataLabels+"&amp;";
	webosBuildChartUrl += "chds=0,"+parseInt((maxValue+1)*1.1);
	
	//Mojo.Log.info("webosBuildChartUrl chart URL: "+webosBuildChartUrl);
	
	$('webosBuildChart').innerHTML = "<img src="+webosBuildChartUrl+" />";
	
}

AllDataAssistant.prototype.readWebosVersionSuccess = function(response) {

	//Mojo.Log.info("WebOS Version response: "+response.responseText.trim());
	
	this.webosVersionList.clear();
	
	var xmlobject = (new DOMParser()).parseFromString(response.responseText.trim(), "text/xml");	
	
	var dataValues = "", dataLabels = "", maxValue = 1;
	
	var seriesNode = xmlobject.getElementsByTagName("series")[0];
	var seriesData = [];
	
	for(var i = 0; i < seriesNode.childNodes.length; i++){
	
		if(seriesNode.childNodes[i].nodeName == 'value'){
		
			seriesData.push( {"xid": seriesNode.childNodes[i].getAttributeNode("xid").nodeValue, "name": seriesNode.childNodes[i].childNodes[0].nodeValue} );
				
			if(dataLabels == "") {
				dataLabels = seriesNode.childNodes[i].childNodes[0].nodeValue.replace(" ","_").replace(" ","_").replace(" ","_").replace(" ","_");
			} else {
				dataLabels += "|"+seriesNode.childNodes[i].childNodes[0].nodeValue.replace(" ","_").replace(" ","_").replace(" ","_").replace(" ","_");
			}
				
		}
	
	}
	
	
	var graphNode = xmlobject.getElementsByTagName("graph")[0];
	var graphData = [];
	
	for(var j = 0; j < graphNode.childNodes.length; j++){
	
		if(graphNode.childNodes[j].nodeName == 'value'){
		
			graphData.push({"xid": graphNode.childNodes[j].getAttributeNode("xid").nodeValue, "value": graphNode.childNodes[j].childNodes[0].nodeValue});
			
			maxValue = Math.max(maxValue,parseInt(graphNode.childNodes[j].childNodes[0].nodeValue));
			
			if(dataValues == "") {
				dataValues = graphNode.childNodes[j].childNodes[0].nodeValue.replace(" ","_").replace(" ","_").replace(" ","_").replace(" ","_");
			} else {
				dataValues += ","+graphNode.childNodes[j].childNodes[0].nodeValue.replace(" ","_").replace(" ","_").replace(" ","_").replace(" ","_");
			}
		
		}
	
	}
	
	
	for(var k = 0; k < seriesData.length; k++){
	
		for(var l = 0; l < graphData.length; l++){
		
			if(seriesData[k].xid == graphData[l].xid) {
			
				this.webosVersionList.push({"label": seriesData[k].name, "title": graphData[l].value});
			
			}
		}
	}	
	
	//Mojo.Log.info("Final webosVersionList list: %j",this.webosVersionList);
	
	this.controller.modelChanged(this.webosVersionListModel);
	
	
	var webosVersionChartUrl = "https://chart.googleapis.com/chart?";
	webosVersionChartUrl += "cht=bvs&amp;";
	webosVersionChartUrl += "chs=310x160&amp;";
	webosVersionChartUrl += "chco=4D89F9&amp;";
	webosVersionChartUrl += "chd=t:"+dataValues+"&amp;";
	webosVersionChartUrl += "chdl="+dataLabels+"&amp;";
	webosVersionChartUrl += "chds=0,"+parseInt((maxValue+1)*1.1);
	
	//Mojo.Log.info("webosVersionChartUrl chart URL: "+webosVersionChartUrl);
	
	$('webosVersionChart').innerHTML = "<img src="+webosVersionChartUrl+" />";
}

AllDataAssistant.prototype.readCustom1Success = function(response) {

	//Mojo.Log.info("Custom1 response: "+response.responseText.trim());
	
	this.custom1List.clear();
	
	var xmlobject = (new DOMParser()).parseFromString(response.responseText.trim(), "text/xml");	
	
	var dataValues = "", dataLabels = "", maxValue = 1;
	
	var seriesNode = xmlobject.getElementsByTagName("series")[0];
	var seriesData = [];
	
	for(var i = 0; i < seriesNode.childNodes.length; i++){
	
		if(seriesNode.childNodes[i].nodeName == 'value'){
		
			seriesData.push( {"xid": seriesNode.childNodes[i].getAttributeNode("xid").nodeValue, "name": seriesNode.childNodes[i].childNodes[0].nodeValue} );
				
			if(dataLabels == "") {
				dataLabels = seriesNode.childNodes[i].childNodes[0].nodeValue.replace(" ","_").replace(" ","_").replace(" ","_").replace(" ","_");
			} else {
				dataLabels += "|"+seriesNode.childNodes[i].childNodes[0].nodeValue.replace(" ","_").replace(" ","_").replace(" ","_").replace(" ","_");
			}
				
		}
	
	}
	
	
	var graphNode = xmlobject.getElementsByTagName("graph")[0];
	var graphData = [];
	
	for(var j = 0; j < graphNode.childNodes.length; j++){
	
		if(graphNode.childNodes[j].nodeName == 'value'){
		
			graphData.push({"xid": graphNode.childNodes[j].getAttributeNode("xid").nodeValue, "value": graphNode.childNodes[j].childNodes[0].nodeValue});
			
			maxValue = Math.max(maxValue,parseInt(graphNode.childNodes[j].childNodes[0].nodeValue));
			
			if(dataValues == "") {
				dataValues = graphNode.childNodes[j].childNodes[0].nodeValue.replace(" ","_").replace(" ","_").replace(" ","_").replace(" ","_");
			} else {
				dataValues += ","+graphNode.childNodes[j].childNodes[0].nodeValue.replace(" ","_").replace(" ","_").replace(" ","_").replace(" ","_");
			}
		
		}
	
	}
	
	
	for(var k = 0; k < seriesData.length; k++){
	
		for(var l = 0; l < graphData.length; l++){
		
			if(seriesData[k].xid == graphData[l].xid) {
			
				this.custom1List.push({"label": seriesData[k].name, "title": graphData[l].value});
			
			}
		}
	}	
	
	//Mojo.Log.info("Final custom1 list: %j",this.custom1List);
	
	this.controller.modelChanged(this.custom1ListModel);
	
	
	var custom1ChartUrl = "https://chart.googleapis.com/chart?";
	custom1ChartUrl += "cht=bvs&amp;";
	custom1ChartUrl += "chs=310x160&amp;";
	custom1ChartUrl += "chco=4D89F9&amp;";
	custom1ChartUrl += "chd=t:"+dataValues+"&amp;";
	custom1ChartUrl += "chdl="+dataLabels+"&amp;";
	custom1ChartUrl += "chds=0,"+parseInt((maxValue+1)*1.1);
	
	//Mojo.Log.info("custom1 chart URL: "+custom1ChartUrl);
	
	$('custom1Chart').innerHTML = "<img src="+custom1ChartUrl+" />";
	
}

AllDataAssistant.prototype.readCustom2Success = function(response) {

	//Mojo.Log.info("custom2 response: "+response.responseText.trim());
	
	this.custom2List.clear();
	
	var xmlobject = (new DOMParser()).parseFromString(response.responseText.trim(), "text/xml");	
	
	var dataValues = "", dataLabels = "", maxValue = 1;
	
	var seriesNode = xmlobject.getElementsByTagName("series")[0];
	var seriesData = [];
	
	for(var i = 0; i < seriesNode.childNodes.length; i++){
	
		if(seriesNode.childNodes[i].nodeName == 'value'){
		
			seriesData.push( {"xid": seriesNode.childNodes[i].getAttributeNode("xid").nodeValue, "name": seriesNode.childNodes[i].childNodes[0].nodeValue} );
				
			if(dataLabels == "") {
				dataLabels = seriesNode.childNodes[i].childNodes[0].nodeValue.replace(" ","_").replace(" ","_").replace(" ","_").replace(" ","_");
			} else {
				dataLabels += "|"+seriesNode.childNodes[i].childNodes[0].nodeValue.replace(" ","_").replace(" ","_").replace(" ","_").replace(" ","_");
			}
				
		}
	
	}
	
	
	var graphNode = xmlobject.getElementsByTagName("graph")[0];
	var graphData = [];
	
	for(var j = 0; j < graphNode.childNodes.length; j++){
	
		if(graphNode.childNodes[j].nodeName == 'value'){
		
			graphData.push({"xid": graphNode.childNodes[j].getAttributeNode("xid").nodeValue, "value": graphNode.childNodes[j].childNodes[0].nodeValue});
			
			maxValue = Math.max(maxValue,parseInt(graphNode.childNodes[j].childNodes[0].nodeValue));
			
			if(dataValues == "") {
				dataValues = graphNode.childNodes[j].childNodes[0].nodeValue.replace(" ","_").replace(" ","_").replace(" ","_").replace(" ","_");
			} else {
				dataValues += ","+graphNode.childNodes[j].childNodes[0].nodeValue.replace(" ","_").replace(" ","_").replace(" ","_").replace(" ","_");
			}
		
		}
	
	}
	
	
	for(var k = 0; k < seriesData.length; k++){
	
		for(var l = 0; l < graphData.length; l++){
		
			if(seriesData[k].xid == graphData[l].xid) {
			
				this.custom2List.push({"label": seriesData[k].name, "title": graphData[l].value});
			
			}
		}
	}	
	
	//Mojo.Log.info("Final custom2 list: %j",this.custom2List);
	
	this.controller.modelChanged(this.custom2ListModel);
	
	
	var custom2ChartUrl = "https://chart.googleapis.com/chart?";
	custom2ChartUrl += "cht=bvs&amp;";
	custom2ChartUrl += "chs=310x160&amp;";
	custom2ChartUrl += "chco=4D89F9&amp;";
	custom2ChartUrl += "chd=t:"+dataValues+"&amp;";
	custom2ChartUrl += "chdl="+dataLabels+"&amp;";
	custom2ChartUrl += "chds=0,"+parseInt((maxValue+1)*1.1);
	
	//Mojo.Log.info("custom2 chart URL: "+custom2ChartUrl);
	
	$('custom2Chart').innerHTML = "<img src="+custom2ChartUrl+" />";
	
}

AllDataAssistant.prototype.readCustom3Success = function(response) {

	//Mojo.Log.info("custom3 response: "+response.responseText.trim());
	
	this.custom3List.clear();
	
	var xmlobject = (new DOMParser()).parseFromString(response.responseText.trim(), "text/xml");	
	
	var dataValues = "", dataLabels = "", maxValue = 1;
	
	var seriesNode = xmlobject.getElementsByTagName("series")[0];
	var seriesData = [];
	
	for(var i = 0; i < seriesNode.childNodes.length; i++){
	
		if(seriesNode.childNodes[i].nodeName == 'value'){
		
			seriesData.push( {"xid": seriesNode.childNodes[i].getAttributeNode("xid").nodeValue, "name": seriesNode.childNodes[i].childNodes[0].nodeValue} );
				
			if(dataLabels == "") {
				dataLabels = seriesNode.childNodes[i].childNodes[0].nodeValue.replace(" ","_").replace(" ","_").replace(" ","_").replace(" ","_");
			} else {
				dataLabels += "|"+seriesNode.childNodes[i].childNodes[0].nodeValue.replace(" ","_").replace(" ","_").replace(" ","_").replace(" ","_");
			}
				
		}
	
	}
	
	
	var graphNode = xmlobject.getElementsByTagName("graph")[0];
	var graphData = [];
	
	for(var j = 0; j < graphNode.childNodes.length; j++){
	
		if(graphNode.childNodes[j].nodeName == 'value'){
		
			graphData.push({"xid": graphNode.childNodes[j].getAttributeNode("xid").nodeValue, "value": graphNode.childNodes[j].childNodes[0].nodeValue});
			
			maxValue = Math.max(maxValue,parseInt(graphNode.childNodes[j].childNodes[0].nodeValue));
			
			if(dataValues == "") {
				dataValues = graphNode.childNodes[j].childNodes[0].nodeValue.replace(" ","_").replace(" ","_").replace(" ","_").replace(" ","_");
			} else {
				dataValues += ","+graphNode.childNodes[j].childNodes[0].nodeValue.replace(" ","_").replace(" ","_").replace(" ","_").replace(" ","_");
			}
		
		}
	
	}
	
	
	for(var k = 0; k < seriesData.length; k++){
	
		for(var l = 0; l < graphData.length; l++){
		
			if(seriesData[k].xid == graphData[l].xid) {
			
				this.custom3List.push({"label": seriesData[k].name, "title": graphData[l].value});
			
			}
		}
	}	
	
	//Mojo.Log.info("Final custom3 list: %j",this.custom3List);
	
	this.controller.modelChanged(this.custom3ListModel);
	
	
	var custom3ChartUrl = "https://chart.googleapis.com/chart?";
	custom3ChartUrl += "cht=bvs&amp;";
	custom3ChartUrl += "chs=310x160&amp;";
	custom3ChartUrl += "chco=4D89F9&amp;";
	custom3ChartUrl += "chd=t:"+dataValues+"&amp;";
	custom3ChartUrl += "chdl="+dataLabels+"&amp;";
	custom3ChartUrl += "chds=0,"+parseInt((maxValue+1)*1.1);
	
	//Mojo.Log.info("custom3 chart URL: "+custom3ChartUrl);
	
	$('custom3Chart').innerHTML = "<img src="+custom3ChartUrl+" />";
	
}

AllDataAssistant.prototype.readCustom4Success = function(response) {

	//Mojo.Log.info("custom4 response: "+response.responseText.trim());
	
	this.custom4List.clear();
	
	var xmlobject = (new DOMParser()).parseFromString(response.responseText.trim(), "text/xml");	
	
	var dataValues = "", dataLabels = "", maxValue = 1;
	
	var seriesNode = xmlobject.getElementsByTagName("series")[0];
	var seriesData = [];
	
	for(var i = 0; i < seriesNode.childNodes.length; i++){
	
		if(seriesNode.childNodes[i].nodeName == 'value'){
		
			seriesData.push( {"xid": seriesNode.childNodes[i].getAttributeNode("xid").nodeValue, "name": seriesNode.childNodes[i].childNodes[0].nodeValue} );
				
			if(dataLabels == "") {
				dataLabels = seriesNode.childNodes[i].childNodes[0].nodeValue.replace(" ","_").replace(" ","_").replace(" ","_").replace(" ","_");
			} else {
				dataLabels += "|"+seriesNode.childNodes[i].childNodes[0].nodeValue.replace(" ","_").replace(" ","_").replace(" ","_").replace(" ","_");
			}
				
		}
	
	}
	
	
	var graphNode = xmlobject.getElementsByTagName("graph")[0];
	var graphData = [];
	
	for(var j = 0; j < graphNode.childNodes.length; j++){
	
		if(graphNode.childNodes[j].nodeName == 'value'){
		
			graphData.push({"xid": graphNode.childNodes[j].getAttributeNode("xid").nodeValue, "value": graphNode.childNodes[j].childNodes[0].nodeValue});
			
			maxValue = Math.max(maxValue,parseInt(graphNode.childNodes[j].childNodes[0].nodeValue));
			
			if(dataValues == "") {
				dataValues = graphNode.childNodes[j].childNodes[0].nodeValue.replace(" ","_").replace(" ","_").replace(" ","_").replace(" ","_");
			} else {
				dataValues += ","+graphNode.childNodes[j].childNodes[0].nodeValue.replace(" ","_").replace(" ","_").replace(" ","_").replace(" ","_");
			}
		
		}
	
	}
	
	
	for(var k = 0; k < seriesData.length; k++){
	
		for(var l = 0; l < graphData.length; l++){
		
			if(seriesData[k].xid == graphData[l].xid) {
			
				this.custom4List.push({"label": seriesData[k].name, "title": graphData[l].value});
			
			}
		}
	}	
	
	//Mojo.Log.info("Final custom4 list: %j",this.custom4List);
	
	this.controller.modelChanged(this.custom4ListModel);
	
	
	var custom4ChartUrl = "https://chart.googleapis.com/chart?";
	custom4ChartUrl += "cht=bvs&amp;";
	custom4ChartUrl += "chs=310x160&amp;";
	custom4ChartUrl += "chco=4D89F9&amp;";
	custom4ChartUrl += "chd=t:"+dataValues+"&amp;";
	custom4ChartUrl += "chdl="+dataLabels+"&amp;";
	custom4ChartUrl += "chds=0,"+parseInt((maxValue+1)*1.1);
	
	//Mojo.Log.info("custom4 chart URL: "+custom4ChartUrl);
	
	$('custom4Chart').innerHTML = "<img src="+custom4ChartUrl+" />";
	
}



